<template>
  <div class="xtx-goods-page" v-if="goodsList.categories">
    <div class="container">
      <!-- 面包屑 -->
      <XtxBread>
        <XtxBreadItem to="/">首页</XtxBreadItem>
        <XtxBreadItem :to="`/Category/${goodsList.categories[1].id}`">{{
          goodsList.categories[1].name
        }}</XtxBreadItem>
        <XtxBreadItem :to="`/category/sub/${goodsList.categories[0].id}`">{{
          goodsList.categories[0].name
        }}</XtxBreadItem>
        <XtxBreadItem to="/">{{ goodsList.name }}</XtxBreadItem>
      </XtxBread>
      <!-- 商品信息 -->
      <div class="goods-info">
        <!-- 图片预览区 -->
        <div class="media">
          <GoodsImage :images="goodsList.mainPictures" />
          <!-- 销量组件 -->
          <GoodsSales :goods="goodsList" />
        </div>
        <!-- 商品信息区 -->
        <div class="spec">
          <GoodName :goods="goodsList" />
          <!-- sku组件 -->
          <Sku :goods="goodsList" @change="skuChange" />
          <!-- 数据组件 -->
          <XtxNumbox v-model="num" />
          <!-- 按钮组件 -->
          <XtxButton type="primary" style="margin-top: 20px"
            >加入购物车</XtxButton
          >
        </div>
      </div>
      <!-- 商品详情 -->
      <div class="goods-footer">
        <div class="goods-article">
          <!-- 商品+评价 -->
          <div class="goods-tabs">
            <GoodsTabs />
          </div>
        </div>
        <!-- 24热榜+专题推荐 -->
        <div class="goods-aside"></div>
      </div>
    </div>
  </div>
</template>

<script>
// 导入面包屑API
import { findGoods } from '@/api/goods.js'
import { ref, onMounted } from 'vue'
import { useRoute } from 'vue-router'
// 导入图片组件
import GoodsImage from './components/goods-image.vue'
import GoodsSales from './components/goods-sales.vue'
import GoodName from './components/goods-name.vue'
import GoodsTabs from './components/goods-tabs.vue'

import Sku from './Sku/index.vue'
export default {
  name: 'XtxGoodsPage',
  components: {
    GoodsImage,
    GoodsSales,
    GoodName,
    GoodsTabs,
    Sku
  },
  setup () {
    const route = useRoute()
    const goodsList = ref({})
    async function getGood () {
      const res = await findGoods(route.params.id)
      console.log(res)
      goodsList.value = res.result
    }
    onMounted(() => {
      getGood()
    })

    function skuChange (sku) {
      console.log(sku)
    }

    // 商品数量
    const num = ref(1)
    return {
      goodsList,
      skuChange,
      num
    }
  }
}
</script>

<style scoped lang='less'>
.goods-info {
  min-height: 600px;
  background: #fff;
  display: flex;
  .media {
    width: 580px;
    height: 600px;
    padding: 30px 50px;
  }
  .spec {
    flex: 1;
    padding: 30px 30px 30px 0;
  }
}
.goods-info {
  min-height: 600px;
  background: #fff;
}
.goods-footer {
  display: flex;
  margin-top: 20px;
  .goods-article {
    width: 940px;
    margin-right: 20px;
  }
  .goods-aside {
    width: 280px;
    min-height: 1000px;
  }
}
.goods-tabs {
  min-height: 600px;
  background: #fff;
}
.goods-warn {
  min-height: 600px;
  background: #fff;
  margin-top: 20px;
}
</style>
